/* GSStocksAddAction.java
 *
 * Project/Product: JZCG-XMBUS
 *
 * Modify Information:
 * =============================================================================
 *   Author	Date       Description
 *   ----------	---------- ---------------------------------------------------
 *   peng.ning	2008-8-27	First release
 *
 * Licensed Materials - Property of APEP
 * =============================================================================
 *    (C) COPYRIGHT Shanghai Auto Mart E-Procurement Co., Ltd. 2007 - 2008
 *    All Rights Reserved.
 *
 *    This software is the confidential and proprietary information of
 *    Shanghai Auto Mart E-Procurement Co., Ltd. ("Confidential Information").
 *    You shall not disclose such Confidential Information and shall use it only
 *    in accordance with the terms of the license agreement you entered into 
 *    with Shanghai Auto Mart E-Procurement Co., Ltd.
 *
 * Noties:
 * =============================================================================
 * 
 */

package com.hitrust.gs.action;

import java.util.ArrayList;

import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.business.GSStocksProcesser;
import com.hitrust.gs.form.GSStocksDetailForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.util.date.DateUtil;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.vo.GSStocksDetailVO;
import com.hitrust.gs.vo.GSStocksVO;

public class GSStocksAddAction extends GSBaseAction {

    /* (non-Javadoc)
     * @see com.hitrust.gs.service.GSBaseAction#execute(com.hitrust.gs.service.GSBaseForm)
     */
    public String execute(GSBaseForm aForm) throws Exception {
        // TODO Auto-generated method stub
        GSOperatorBean operatorBean = (GSOperatorBean)aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
        GSStocksDetailForm sdf=(GSStocksDetailForm) aForm;
        //转换为vo对象
        GSStocksVO svo=new GSStocksVO();
        svo.gs_stocks_id=sdf.getStocksid();
        svo.gs_workcorp_id=sdf.getOrgid();
        svo.gs_stocks_person=sdf.getStocksperson();
        svo.gs_stocks_dept=sdf.getStocksdept();
        svo.gs_stocks_total=Double.parseDouble(sdf.getTotal())+"";
        svo.gs_stocks_state=sdf.getStocksstate();
        svo.gs_stocks_datestart=sdf.getStocksdate();
        svo.gs_stocks_remark=sdf.getStocksremark();
        svo.gs_operator_id=operatorBean.getGs_oper_id();
        svo.gs_operator_date=DateUtil.getCurrentDate("yyyy-MM-dd HH:mm:ss");
        svo.gs_shipment_id=sdf.getShipid();
        String[] manuid=sdf.getSdetailmanid();
        String[] manuname=sdf.getSdetailmanname();
        String[] manutype=sdf.getSdetailmantype();
        String[] manuunit=sdf.getSdetailunit();
        String[] manucount=sdf.getSdetailcount();
        String[] manuuse=sdf.getSdetailuse();
        String[] manuremark=sdf.getSdetailremark();
        String[] manustate=sdf.getSdetailstate();
        String[] manucatid=sdf.getSdetailcatid();
        String[] manuconid=sdf.getSdetailconid();
        String[] manuproid=sdf.getSdetailproid();
        String[] mode=sdf.getMode();
        ArrayList array=new ArrayList();
        String str="";
        for (int i = 0; i < manuid.length; i++) {
            int a=i+1;
            if(a<10){
                str="000";
            }else if(a>=10&&a<100){
                str="00";
            }else if(a>=100&&a<1000){
                str="0";
            }
            GSStocksDetailVO sdvo=new GSStocksDetailVO();
            sdvo.gs_detail_id=sdf.getStocksid()+str+a;//明细编号
            sdvo.gs_stocks_id=sdf.getStocksid();
            sdvo.gs_manufacture_id=manuid[i];
            sdvo.gs_manufacture_name=manuname[i];
            sdvo.gs_manufacture_type=manutype[i];
            sdvo.gs_detail_unitprice=Double.parseDouble(manuunit[i]);
            sdvo.gs_detail_count=Double.parseDouble(manucount[i]);
            sdvo.gs_detail_use=manuuse[i];
            sdvo.gs_detail_remark=manuremark[i];
            sdvo.gs_detail_state=manustate[i];
            sdvo.gs_manufacture_category_id=manucatid[i];
            sdvo.gs_concentricity_id=manuconid[i];
            sdvo.gs_provider_id=manuproid[i];
            sdvo.gs_org_state="0";
            sdvo.gs_prov_state="0";
            sdvo.gs_contents="";
            sdvo.Gs_balance_month="";
            sdvo.gs_balance_mode=mode[i];
            array.add(sdvo);
        }
        try {
            GSStocksProcesser stprocesser=new GSStocksProcesser();
            stprocesser.savestocks(svo, array);
            aForm.getRequest().setAttribute("message", "库存领用单录入成功！");
            aForm.getRequest().setAttribute("action", "A181101.do");
        } catch (GSException e) {
            
            aForm.getRequest().setAttribute("message", e.getMessage());
            aForm.getRequest().setAttribute("backstep", "-1");
        }
        return GSBaseConstants.FORWARD_SUCCESS;
    }

}
